
from email.mime.text import MIMEText   #邮件的正文
import smtplib,random
def getyzm():
    yzm=""
    for i in range(6):
        yzm+=str(random.randint(0,9))
    return yzm

def getmailclient(receiver):
    mail = receiver.split("@")[1]
    mail = mail.split(".")[0]
    remail = "https://mail."+mail+".com"
    return remail
def netmail(receiver):
    user="lwjidea@163.com"
    pwd="lwjidea123"
    sender="lwjidea@163.com"
    receiver=[receiver]
    title = "即住邮箱验证"
    mail_host = "smtp.163.com"   #163的smtp的服务器
    yzm = getyzm()
    content = "<a href='www.baidu.com'>你好</a>"
    # content = "验证码为: "+yzm+"\n如果不是本人操作,请忽略"
    message = MIMEText(content,"plain","utf-8")  #内容，格式，编码
    message["From"] = sender
    message["To"] = ",".join(receiver)
    message["Subject"] = title
    try:
        smtpObj = smtplib.SMTP_SSL(mail_host,465)
        smtpObj.login(user,pwd)
        smtpObj.sendmail(sender,receiver,message.as_string())
        remail = getmailclient(receiver[0])
        return yzm,remail
    except smtplib.SMTPException  as e:
        print(e)
        return

netmail("1484496615@qq.com")
